package com.bjpowernode.task;

import com.bjpowernode.DlykServerApplication;
import com.bjpowernode.entities.TDicType;
import com.bjpowernode.entities.TProduct;
import com.bjpowernode.enums.DicEnum;
import com.bjpowernode.services.DicTypeService;
import com.bjpowernode.services.ProductService;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@EnableScheduling
@Component
public class DataTask {
    @Resource
    private DicTypeService dicTypeService;
    @Resource
    private ProductService productService;

    @Scheduled(cron = "0 0 0/3 * * ?")
    public void task() {
        System.out.println("执行：" + new Date());
        List<TDicType> tDicTypeList = dicTypeService.getDicTypes();
        for (TDicType tDicType : tDicTypeList)
            DlykServerApplication.cacheMap.put(tDicType.getTypeCode(), tDicType.getDicValueList());
        List<TProduct> productList = productService.getProducts();
        DlykServerApplication.cacheMap.put(DicEnum.INTENTION_PRODUCT.getCode(), productList);
    }
}

